package com.acwing.partition3;

import java.io.*;
import java.util.HashMap;
import java.util.Map;

/**
 * @author `RKC`
 * @date 2022/2/11 18:57
 */
public class AC239奇偶游戏_扩展域 {

    private static final int N = 40010, BASE = N / 2;
    private static Map<Integer, Integer> map = new HashMap<>(N);
    private static int[] parent = new int[N];

    private static int n = 0, m = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = Integer.parseInt(reader.readLine());
        m = Integer.parseInt(reader.readLine());
        n = 0;
        int ans = m;
        for (int i = 0; i < N; i++) parent[i] = i;
        for (int i = 1; i <= m; i++) {
            String[] ss = reader.readLine().split(" ");
            int a = Integer.parseInt(ss[0]) - 1, b = Integer.parseInt(ss[1]);
            a = get(a);
            b = get(b);
            if ("odd".equals(ss[2])) {
                //要求是异类，如果同类的两个条件成立，就说明错误
                if (find(a) == find(b)) {
                    ans = i - 1;
                    break;
                }
                parent[find(a + BASE)] = find(b);
                parent[find(a)] = find(b + BASE);
            } else {
                //要求是同类，如果异类的两个条件成立，就说明错误
                if (find(a + BASE) == find(b)) {
                    ans = i - 1;
                    break;
                }
                parent[find(a)] = find(b);
                parent[find(a + BASE)] = find(b + BASE);
            }
        }
        writer.write(ans + "\n");
        writer.flush();
    }

    private static int get(int x) {
        if (!map.containsKey(x)) map.put(x, ++n);
        return map.get(x);
    }

    private static int find(int x) {
        if (x != parent[x]) parent[x] = find(parent[x]);
        return parent[x];
    }
}
